import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesUtil {
    public static void propertiesOutIput(String path, String key, String value) {
        Properties properties = new Properties();
        properties.getProperty(key, value);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(path);
            properties.store(fos, null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static Properties propertiesIput(String path) {
        FileInputStream fis = null;
        Properties properties = new Properties();
        try {
            fis = new FileInputStream(path);
            properties.load(fis);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return properties;
    }

    public static void main(String[] args) {
        // 将下面字符串?后面的键值对保存到proerties文件中
        //  String url = "http://www.lovo.com/index?name=aaaaaa&age=20&gender=男";
        String url = "http://www.lovo.com/index?name=aaaaaa&age=20&gender=男";
        String str = url.substring(url.indexOf("?") + 1);
        String[] strs = str.split("&");
        String[] strss = null;
        for (int i = 0; i < strs.length; i++) {
            strss = strs[i].split("=");
            propertiesOutIput("1.properties",strss[0],strss[1]);
        }
    }
}
